
using System;
using System.Text;
using SpotifyGenNHibernate.CEN;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Criterion;
using NHibernate.Exceptions;
using SpotifyGenNHibernate.EN.Spotify;

namespace SpotifyGenNHibernate.CAD.Spotify
{
        public partial class AdministradorCAD : BasicCAD, IAdministradorCAD
        {
        public AdministradorCAD() : base ()
        {
        }

        public AdministradorCAD(ISession sessionAux) : base (sessionAux)
        {
        }



        public AdministradorEN ReadOIDDefault (int id)
        {
                AdministradorEN administradorEN = null;

                try
                {
                        SesssionInitializeTransaction ();
                        administradorEN = (AdministradorEN)session.Load (typeof(AdministradorEN),
                                id

                                );
                        SessionCommit ();
                }

                catch (Exception ex) {
                        SessionRollBack ();
                        if (ex is ModelException)
                                throw ex;
                        throw new DataLayerException ("Error in AdministradorCAD.", ex);
                }


                finally
                {
                        SessionClose ();
                }

                return administradorEN;
        }


        public int New_ (AdministradorEN administrador)
        {
                try
                {
                        SesssionInitializeTransaction ();

                        session.Save (administrador);
                        SessionCommit ();
                }

                catch (Exception ex) {
                        SessionRollBack ();
                        if (ex is ModelException)
                                throw ex;
                        throw new DataLayerException ("Error in AdministradorCAD.", ex);
                }


                finally
                {
                        SessionClose ();
                }

                return administrador.Id;
        }

        public void Destroy (int id)
        {
                try
                {
                        SesssionInitializeTransaction ();
                        AdministradorEN administradorEN = (AdministradorEN)session.Load (typeof(AdministradorEN),
                                id

                                );
                        session.Delete (administradorEN);
                        SessionCommit ();
                }

                catch (Exception ex) {
                        SessionRollBack ();
                        if (ex is ModelException)
                                throw ex;
                        throw new DataLayerException ("Error in AdministradorCAD.", ex);
                }


                finally
                {
                        SessionClose ();
                }
        }

        public void Editar (AdministradorEN administrador)
        {
                try
                {
                        SesssionInitializeTransaction ();
                        AdministradorEN administradorEN = (AdministradorEN)session.Load (typeof(AdministradorEN), administrador.Id);

                        administradorEN.Usuario = administrador.Usuario;


                        administradorEN.Password = administrador.Password;

                        session.Update (administradorEN);
                        SessionCommit ();
                }

                catch (Exception ex) {
                        SessionRollBack ();
                        if (ex is ModelException)
                                throw ex;
                        throw new DataLayerException ("Error in AdministradorCAD.", ex);
                }


                finally
                {
                        SessionClose ();
                }
        }
        }
}
